local xionggu = fk.CreateSkill{
    name = "ym1__xionggu",
}
Fk:loadTranslationTable{
    ["ym1__xionggu"] = "凶锢",
    [":ym1__xionggu"] = "回合结束时，若你本回合因使用或弃置而失去了至少两张牌，且这些牌花色各不相同，你可以令一名角色失去1点体力并执行一个额外回合。",
    ["@ym1__xionggu-turn"] = "凶锢",
    ["#ym1__xionggu"] = "凶锢：令一名角色失去1点体力并执行一个额外回合",

    ["$ym1__xionggu1"] = "当今天子乃我所立，他敢怎样？",
    ["$ym1__xionggu2"] = "我兄弟三人同掌禁军，有何所惧？",
}

xionggu:addEffect(fk.TurnEnd, {
    can_trigger = function (self, event, target, player, data)
        if player == target and player:hasSkill(xionggu.name) then
            local room = player.room
            local ids = {}
            local suits = {}
            room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
                for _, move in ipairs(e.data) do
                    if move.from == player then
                        for _, info in ipairs(move.moveInfo) do
                            if table.contains({fk.ReasonUse, fk.ReasonDiscard}, move.moveReason)
                            and table.contains({Card.PlayerHand, Card.PlayerEquip}, info.fromArea) then
                                table.insertIfNeed(ids, info.cardId)
                                table.insertIfNeed(suits, Fk:getCardById(info.cardId):getSuitString(true))
                            end
                        end
                    end
                end
            end, Player.HistoryTurn)
            return #ids == #suits and #ids > 1
        end
    end,
    on_cost = function (self, event, target, player, data)
        local tos = player.room:askToChoosePlayers(player, {
            max_num = 1,
            min_num = 1,
            targets = player.room.alive_players,
            skill_name = xionggu.name,
            prompt = "#ym1__xionggu",
        })
        if #tos > 0 then
            event:setCostData(self, {tos = tos})
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local to = event:getCostData(self).tos[1]
        room:loseHp(to, 1, xionggu.name)
        to:gainAnExtraTurn(true, xionggu.name)
    end,
})

xionggu:addEffect(fk.AfterCardsMove, {
    can_refresh = function(self, event, target, player, data)
        if not player:hasSkill(xionggu.name) or player.room.current ~= player then return end
        for _, move in ipairs(data) do
            if move.from == player then
                for _, info in ipairs(move.moveInfo) do
                    if table.contains({fk.ReasonUse, fk.ReasonDiscard}, move.moveReason)
                    and table.contains({Card.PlayerHand, Card.PlayerEquip}, info.fromArea) then
                        return true
                    end
                end
            end
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local ids = {}
        local suits = {}
        room.logic:getEventsOfScope(GameEvent.MoveCards, 999, function(e)
            for _, move in ipairs(e.data) do
                if move.from == player then
                    for _, info in ipairs(move.moveInfo) do
                        if table.contains({fk.ReasonUse, fk.ReasonDiscard}, move.moveReason)
                        and table.contains({Card.PlayerHand, Card.PlayerEquip}, info.fromArea) then
                            table.insertIfNeed(ids, info.cardId)
                            table.insertIfNeed(suits, Fk:getCardById(info.cardId):getSuitString(true))
                        end
                    end
                end
            end
        end, Player.HistoryTurn)
        if #suits == #ids then
            room:setPlayerMark(player, "@ym1__xionggu-turn", suits)
        else
            room:setPlayerMark(player, "@ym1__xionggu-turn", "×")
        end
    end,
})

return xionggu